//
//  ReferTwoViewController.m
//  Village
//
//  Created by longrise on 2017/9/25.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "ReferTwoViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>
@interface ReferTwoViewController ()<UIWebViewDelegate>
@property (nonatomic ,strong) UIWebView *web;
@property (nonatomic ,strong) JSContext *context;
@property (nonatomic ,strong)NSString *adderss;
@property (nonatomic ,strong)NSString *adderss1;
@property (nonatomic ,strong)NSString *areaid;
@end

@implementation ReferTwoViewController
- (void)setParams:(id)obj block:(LongriseRouterBlock)block
{
    NSDictionary *dict = (NSDictionary *)obj;
    NSString *str  = dict[@"province"];
    NSString *str1 = dict[@"city"];
    NSString *str2 = dict[@"district"];
    NSString *str3 = dict[@"town"];
    NSString *str4 = dict[@"village"];
    _areaid = dict[@"areaid"];
    
    if (str1 == nil || [str1 isEqualToString:@""]){
        _adderss = [NSString stringWithFormat:@"%@",str];
        _adderss1 = str;
    }else if (str2 == nil || [str2 isEqualToString:@""] ) {
        _adderss = [NSString stringWithFormat:@"%@·%@",str,str1];
         _adderss1 = str1;
    }else if (str3 == nil || [str3 isEqualToString:@""]) {
        _adderss = [NSString stringWithFormat:@"%@·%@·%@",str,str1,str2];
          _adderss1 = str2;
    }else if (str4 == nil || [str4 isEqualToString:@""]) {
        _adderss = [NSString stringWithFormat:@"%@·%@·%@·%@",str,str1,str2,str3];
          _adderss1 = str3;
    }else{
        _adderss = [NSString stringWithFormat:@"%@·%@·%@·%@·%@",str,str1,str2,str3,str4];
          _adderss1 = str4;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"村落查询";
    self.view.backgroundColor = [UIColor whiteColor];
    [self addview];
}

- (void)addview{
    [MBProgressHUD showMessage:@"正在加载..." toView:self.navigationController.view];
    _web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, KDeviceHeight - kNavHeight)];
    _web.delegate = self;
    _web.backgroundColor = [UIColor whiteColor];
    NSString *str = [NSString stringWithFormat:@"%@LEAP/web/index.html",IPURL];
    NSURL* url = [NSURL URLWithString:str];//创建URL
    NSURLRequest* request = [NSURLRequest requestWithURL:url];//创建NSURLRequest
    [_web loadRequest:request];
    [self.view addSubview:_web];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
     [MBProgressHUD hideHUDForView:self.navigationController.view];
//    JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//    NSString* jsCode = [NSString stringWithFormat:@"lcucapp.stat({%@:%@,%@:%@});",@"areaid",_areaid,@"area",_adderss];
//    NSString* jsCode = [NSString stringWithFormat:@"lcucapp.stat(('%@', '%@'));",_areaid,_adderss];
//    [context evaluateScript:jsCode];//通过oc方法调用js的alert
    NSString *jsStr = [NSString stringWithFormat:@"javascript:lcucappstat({'areaid':'%@','area':'%@'})",_areaid,_adderss];
     [_web stringByEvaluatingJavaScriptFromString:jsStr];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
